package com.weng.apistarter.crud.service.impl;

import com.weng.apistarter.crud.entity.Role;
import com.weng.apistarter.crud.mapper.RoleMapper;
import com.weng.apistarter.crud.service.IRoleService;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.framework.dao.mybatis.model.page.PageModel;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


/**
 * 角色 服务实现类
 *
 * @author weng
 * @date 2021-10-07 21:43:17
 *
 */ 
@Slf4j
@Service
public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implements IRoleService {
	@Autowired
	private RoleMapper roleMapper;
	

	/**
	 * 分页查询角色
	 * @return
	 */
	@Override
	public IPage<Role> list(Integer pageNo,Integer pageSize) {
		QueryWrapper<Role> qw = new QueryWrapper<>();
		IPage<Role> page = new PageModel<>(pageNo,pageSize);
		return roleMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个角色
	 * @param id
	 * @return
	 */
	@Override
	public Role getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个角色
	 * @param role
	 * @return
	 */
	@Override
	public Role add(Role role)  {
		
		roleMapper.insert(role);
		return role;
	}

	/**
	 * 更新单个角色
	 * @param role
	 * @return
	 * @
	 */
	@Override
	public int update(Role role)  {
		
		return roleMapper.updateById(role);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] roleIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(roleIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
